<?php

// [ 获取PK10计划分页列表 ]
// GET pk10.planVolist
// http://sg.51hub.cn/api?pk10.planVolist
// http://sg.io/api?pk10.planVolist

namespace app\api\resource\pk10;
use think\Db;
use app\api\lib\Page;

class PlanVolist
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '获取PK10计划分页列表';
    // 参数
    public $_param  = [
        'page' => '请求页',
        'show' => '每页记录数量',
    ];

    public function run(&$request)
    {
        $page  = $request->get('page/d',1);
        $show  = $request->get('show/d',10);

        $table    = 'plan';
        $where[]  = ['v1_loc','neq',0];
        $order    = 'no DESC';
        $pagelist = Page::run($table,$where,$order,$page,$show);
        // p($pagelist);die;

        if ( !empty($pagelist['list']) ) {
            foreach ($pagelist['list'] as $key => $val) {
                $pagelist['list'][$key]['v1_hash'] = explode(',',$val['v1_hash']);
                $pagelist['list'][$key]['v2_hash'] = explode(',',$val['v2_hash']);
                $pagelist['list'][$key]['v3_hash'] = explode(',',$val['v3_hash']);
                $pagelist['list'][$key]['v4_hash'] = explode(',',$val['v4_hash']);
                $pagelist['list'][$key]['v5_hash'] = explode(',',$val['v5_hash']);
            }
        }

        // 如果请求第一页,查询最新计划预测
        if (1 == $page) {
            $pagelist['plan'] = Db::name('plan')->where('v1_loc',0)->order('no DESC')->find();
            $pagelist['plan']['v1_hash'] = explode(',',$pagelist['plan']['v1_hash']);
            $pagelist['plan']['v2_hash'] = explode(',',$pagelist['plan']['v2_hash']);
            $pagelist['plan']['v3_hash'] = explode(',',$pagelist['plan']['v3_hash']);
            $pagelist['plan']['v4_hash'] = explode(',',$pagelist['plan']['v4_hash']);
            $pagelist['plan']['v5_hash'] = explode(',',$pagelist['plan']['v5_hash']);
        }

        return [200,$pagelist];
    }
}
